Return to start page

Systems/Character/Struct Talk Log.j

Code

		
1			library AStructSystemsCharacterTalkLog requires AStructCoreGeneralVector, AStructSystemsCharacterAbstractCharacterSystem
2
3 //! runtextmacro A_VECTOR("private", "AStringVectorVector", "AStringVector", "0", "100", "8192") /// @todo JASS_MAX_ARRAY_SIZE, vJass bug.
4
5 struct ATalkLog extends AAbstractCharacterSystem
6 private AIntegerVector m_talks
7 private AStringVectorVector m_speeches
8
9 public method addMessage takes ATalk talk, string message returns nothing
10 local integer index = this.m_talks.find(talk)
11 if (index == -1) then
12 call this.m_talks.pushBack(talk)
13 call this.m_speeches.pushBack(AStringVector.create())
14 set index = this.m_talks.backIndex()
15 endif
16 call this.m_speeches[index].pushBack(message)
17 endmethod
18
19 public method message takes ATalk talk, integer index returns string
20 local integer talkIndex = this.m_talks.find(talk)
21 if (talkIndex == -1) then
22 return null
23 endif
24 if (index >= this.m_speeches[talkIndex].size() or index < 0) then
25 return null
26 endif
27 return this.m_speeches[talkIndex].at(index)
28 endmethod
29
30 public method talk takes ATalk talk returns AStringVector
31 local integer talkIndex = this.m_talks.find(talk)
32 if (talkIndex == -1) then
33 return 0
34 endif
35 return AStringVector.createByOther(this.m_speeches[talkIndex])
36 endmethod
37
38 public static method create takes ACharacter character returns thistype
39 local thistype this = thistype.allocate(character)
40 //members
41 set this.m_talks = AIntegerVector.create()
42 set this.m_speeches = AStringVectorVector.create()
43 return this
44 endmethod
45
46 public method onDestroy takes nothing returns nothing
47 //members
48 call this.m_talks.destroy()
49 loop
50 exitwhen (this.m_speeches.empty())
51 call this.m_speeches[this.m_speeches.backIndex()].destroy()
52 call this.m_speeches.popBack()
53 endloop
54 call this.m_speeches.destroy()
55 endmethod
56 endstruct
57
58 endlibrary